import Immutable from 'seamless-immutable';
import * as types from '../constants/ActionTypes';

const officialChannel = Immutable.from({
  channelData: {},
  oneChannel: {},
  saveMsg: {}
});
export default function officialChannelReducer(state = officialChannel, action) {
  const { payload, type } = action;
  switch (type) {
    case types.FETCH_OFFICIAL_CHANNEL:
      return state.setIn(['channelData'], payload);
    case types.FETCH_ONE_OFFICIAL_CHANNEL:
      return state.setIn(['oneChannel'], payload);
    case types.RESTORE_CHANNEL:
      return state.setIn(['oneChannel'], {})
        .setIn(['saveMsg'], {});
    case types.SAVE_CHANNEL_ERROR_MSG:
      return state.setIn(['saveMsg'], payload.data);
    case types.RESET_SAVE_ERROR_MSG:
      return state.setIn(['saveMsg'], {});
    default:
      return state;
  }
}
